package com.ken.apollo.commons.exception;

import com.ken.apollo.commons.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler
    public R handleException(Exception e) {
        log.error("【全局异常】服务器异常！", e);
        return R.fail("服务器异常");
    }

    @ExceptionHandler(ServiceException.class)
    public R handleServiceException(ServiceException e) {
        return R.fail(e.getCode(), e.getMessage());
    }
}
